
package db;

import model.model;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import javax.sql.DataSource;
import java.sql.SQLException;
import java.util.List;

/**
 * @author:合肥工业大学 管理学院 钱洋
 * @email:1563178220@qq.com
 * @
 */

public class MYSQLControl {
    static final Log logger = LogFactory.getLog(MYSQLControl.class);
    static DataSource ds = MyDataSource.getDataSource("jdbc:mysql://rm-wz9v9e07mh753tk321o.mysql.rds.aliyuncs.com:3306/car_spider");


    public static int inserCarRecall(List<model> Models) {

        Object[][] params = new Object[Models.size()][39];
        int c = 0;  //success number of update
        int[] sum;
        QueryRunner qr = new QueryRunner(ds);
        for (int i = 0; i < Models.size(); i++) {


            params[i][0] = Models.get(i).getFactory();
            params[i][1] = Models.get(i).getBrand();
            params[i][2] = Models.get(i).getCar_big();
            params[i][3] = Models.get(i).getCar_small();

            params[i][4] = Models.get(i).getFactory_price();
            params[i][5] = Models.get(i).getSHENZHEN_price();
            params[i][6] = Models.get(i).getTime();
            params[i][7] = Models.get(i).getCar_level();
            params[i][8] = Models.get(i).getCar_body();
            params[i][9] = Models.get(i).getDynamic_type();
            params[i][10] = Models.get(i).getEngine();
            params[i][11] = Models.get(i).getMaximum_power_torque();
            params[i][12] = Models.get(i).getTransmission_type();
            params[i][13] = Models.get(i).getFuel_consumption();
            params[i][14] = Models.get(i).getAcceleration_time();
            params[i][15] = Models.get(i).getTop_speed();
            params[i][16] = Models.get(i).getEnvironmental_standard();
            params[i][17] = Models.get(i).getWarranty_policy();

            params[i][18] = Models.get(i).getLength_width_height();
            params[i][19] = Models.get(i).getWheelbase();
            params[i][20] = Models.get(i).getWeight();
            params[i][21] = Models.get(i).getSeats_number();
            params[i][22] = Models.get(i).getLuggage_capacity();
            params[i][23] = Models.get(i).getTank_capacity();
            params[i][24] = Models.get(i).getFront_tire_specification();
            params[i][25] = Models.get(i).getRear_tire_specification();
            params[i][26] = Models.get(i).getSpare_tire();
            params[i][27] = Models.get(i).getMinimum_turning_diameter();
            params[i][28] = Models.get(i).getMinimum_ground_clearance();

            params[i][29] = Models.get(i).getDisplacement();
            params[i][30] = Models.get(i).getMaximum_power();
            params[i][31] = Models.get(i).getMaximum_horsepower();
            params[i][32] = Models.get(i).getMaximum_power_speed();
            params[i][33] = Models.get(i).getMaximum_torque();
            params[i][34] = Models.get(i).getMaximum_torque_speed();
            params[i][35] = Models.get(i).getOil_supply_way();
            params[i][36] = Models.get(i).getFuel_label();
            params[i][37] = Models.get(i).getTransmission_type1();
            params[i][38] = Models.get(i).getBlock_number();







        }


        try {
            //qr.update(String.format("INSERT INTO car_complain VALUES (%s,%s,%s,%s,%s,%s,%s,%s)", (String)params[i][0],(String)params[i][1],(String)params[i][2],(String)params[i][3],(String)params[i][4],(String)params[i][5],params[i][6],params[i][7]));
            sum = qr.batch("INSERT INTO car_price_detail_stop VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", params);
        } catch (SQLException e) {
            System.out.println(e);
        }


        System.out.println("数据入库完毕");

        return c;

    }

}



